<!DOCTYPE html><html><head><title>Coverage</title><script>

headings = [];

onload = function(){
  headings = document.querySelectorAll('h2');
};

onscroll = function(e){
  var heading = find(window.scrollY);
  if (!heading) return;
  var links = document.querySelectorAll('#menu a')
    , link;

  for (var i = 0, len = links.length; i < len; ++i) {
    link = links[i];
    link.className = link.getAttribute('href') == '#' + heading.id
      ? 'active'
      : '';
  }
};

function find(y) {
  var i = headings.length
    , heading;

  while (i--) {
    heading = headings[i];
    if (y > heading.offsetTop) {
      return heading;
    }
  }
}
</script><style>

body {
  font: 14px/1.6 "Helvetica Neue", Helvetica, Arial, sans-serif;
  margin: 0;
  color: #2C2C2C;
  border-top: 2px solid #ddd;
}

#coverage {
  padding: 60px;
}

h1 a {
  color: inherit;
  font-weight: inherit;
}

h1 a:hover {
  text-decoration: none;
}

.onload h1 {
  opacity: 1;
}

h2 {
  width: 80%;
  margin-top: 80px;
  margin-bottom: 0;
  font-weight: 100;
  letter-spacing: 1px;
  border-bottom: 1px solid #eee;
}

a {
  color: #8A6343;
  font-weight: bold;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul {
  margin-top: 20px;
  padding: 0 15px;
  width: 100%;
}

ul li {
  float: left;
  width: 40%;
  margin-top: 5px;
  margin-right: 60px;
  list-style: none;
  border-bottom: 1px solid #eee;
  padding: 5px 0;
  font-size: 12px;
}

ul::after {
  content: '.';
  height: 0;
  display: block;
  visibility: hidden;
  clear: both;
}

code {
  font: 12px monaco, monospace;
}

pre {
  margin: 30px;
  padding: 30px;
  border: 1px solid #eee;
  border-bottom-color: #ddd;
  -webkit-border-radius: 2px;
  -moz-border-radius: 2px;
  -webkit-box-shadow: inset 0 0 10px #eee;
  -moz-box-shadow: inset 0 0 10px #eee;
  overflow-x: auto;
}

img {
  margin: 30px;
  padding: 1px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  -webkit-box-shadow: 0 3px 10px #dedede, 0 1px 5px #888;
  -moz-box-shadow: 0 3px 10px #dedede, 0 1px 5px #888;
  max-width: 100%;
}

footer {
  background: #eee;
  width: 100%;
  padding: 50px 0;
  text-align: right;
  border-top: 1px solid #ddd;
}

footer span {
  display: block;
  margin-right: 30px;
  color: #888;
  font-size: 12px;
}

#menu {
  position: fixed;
  font-size: 12px;
  overflow-y: auto;
  top: 0;
  right: 0;
  margin: 0;
  height: 100%;
  padding: 15px 0;
  text-align: right;
  border-left: 1px solid #eee;
  -moz-box-shadow: 0 0 2px #888
     , inset 5px 0 20px rgba(0,0,0,.5)
     , inset 5px 0 3px rgba(0,0,0,.3);
  -webkit-box-shadow: 0 0 2px #888
     , inset 5px 0 20px rgba(0,0,0,.5)
     , inset 5px 0 3px rgba(0,0,0,.3);
  -webkit-font-smoothing: antialiased;
  background: url("");
}

#logo {
  position: fixed;
  bottom: 10px;
  right: 10px;
  background: rgba(255,255,255,.1);
  font-size: 11px;
  display: block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  -webkit-box-shadow: 0 0 3px rgba(0,0,0,.2);
  -moz-box-shadow: 0 0 3px rgba(0,0,0,.2);
  color: inherit;
}

#menu li a {
  display: block;
  color: white;
  padding: 0 35px 0 25px;
  -webkit-transition: background 300ms;
  -moz-transition: background 300ms;
}

#menu li {
  position: relative;
  list-style: none;
}

#menu a:hover,
#menu a.active {
  text-decoration: none;
  background: rgba(255,255,255,.1);
}

#menu li:hover .cov {
  opacity: 1;
}

#menu li .dirname {
  opacity: .60;
  padding-right: 2px;
}

#menu li .basename {
  opacity: 1;
}

#menu .cov {
  background: rgba(0,0,0,.4);
  position: absolute;
  top: 0;
  right: 8px;
  font-size: 9px;
  opacity: .6;
  text-align: left;
  width: 17px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  padding: 2px 3px;
  text-align: center;
}

#stats:nth-child(2n) {
  display: inline-block;
  margin-top: 15px;
  border: 1px solid #eee;
  padding: 10px;
  -webkit-box-shadow: inset 0 0 2px #eee;
  -moz-box-shadow: inset 0 0 2px #eee;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
}

#stats div {
  float: left;
  padding: 0 5px;
}

#stats::after {
  display: block;
  content: '';
  clear: both;
}

#stats .sloc::after {
  content: ' SLOC';
  color: #b6b6b6;
}

#stats .percentage::after {
  content: ' coverage';
  color: #b6b6b6;
}

#stats .hits,
#stats .misses {
  display: none;
}

.high {
  color: #00d4b4;
}
.medium {
  color: #e87d0d;
}
.low {
  color: #d4081a;
}
.terrible {
  color: #d4081a;
  font-weight: bold;
}

table {
  width: 80%;
  margin-top: 10px;
  border-collapse: collapse;
  border: 1px solid #cbcbcb;
  color: #363636;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
}

table thead {
  display: none;
}

table td.line,
table td.hits {
  width: 20px;
  background: #eaeaea;
  text-align: center;
  font-size: 11px;
  padding: 0 10px;
  color: #949494;
}

table td.hits {
  width: 10px;
  padding: 2px 5px;
  color: rgba(0,0,0,.2);
  background: #f0f0f0;
}

tr.miss td.line,
tr.miss td.hits {
  background: #e6c3c7;
}

tr.miss td {
  background: #f8d5d8;
}

td.source {
  padding-left: 15px;
  line-height: 15px;
  white-space: pre;
  font: 12px monaco, monospace;
}

code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }
</style></head><body><div id="coverage"><h1 id="overview">Coverage</h1><div id="menu"><li><a href="#overview">overview</a></li><li><span class="cov medium">53</span><a href="#model/SessionEntity.js"><span class="dirname">model/</span><span class="basename">SessionEntity.js</span></a></li><li><span class="cov high">100</span><a href="#common.js"><span class="basename">common.js</span></a></li><li><span class="cov high">100</span><a href="#control/ResponseHooks.js"><span class="dirname">control/</span><span class="basename">ResponseHooks.js</span></a></li><li><span class="cov high">100</span><a href="#model/ResponseEntity.js"><span class="dirname">model/</span><span class="basename">ResponseEntity.js</span></a></li><li><span class="cov terrible">22</span><a href="#control/CommandControl.js"><span class="dirname">control/</span><span class="basename">CommandControl.js</span></a></li><a id="logo" href="http://visionmedia.github.com/mocha/">m</a></div><div id="stats" class="medium"><div class="percentage">57%</div><div class="sloc">123</div><div class="hits">71</div><div class="misses">52</div></div><div id="files"><div class="file"><h2 id="model/SessionEntity.js">model/SessionEntity.js</h2><div id="stats" class="medium"><div class="percentage">53%</div><div class="sloc">82</div><div class="hits">44</div><div class="misses">38</div></div><table id="source"><thead><tr><th>Line</th><th>Hits</th><th>Source</th></tr></thead><tbody><tr class="hit"><td class="line">1</td><td class="hits">1</td><td class="source">var net = require('net');</td></tr><tr class="hit"><td class="line">2</td><td class="hits">1</td><td class="source">var util = require('util');</td></tr><tr><td class="line">3</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">4</td><td class="hits">1</td><td class="source">var common = require('../common');</td></tr><tr class="hit"><td class="line">5</td><td class="hits">1</td><td class="source">var ccResponse = require('../control/ResponseHooks');</td></tr><tr class="hit"><td class="line">6</td><td class="hits">1</td><td class="source">var mResponse = require('./ResponseEntity');</td></tr><tr><td class="line">7</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">8</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">9</td><td class="hits"></td><td class="source"> * Store session handle information</td></tr><tr><td class="line">10</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">11</td><td class="hits"></td><td class="source"> * @param id</td></tr><tr><td class="line">12</td><td class="hits"></td><td class="source"> *            {string} Session identifier</td></tr><tr><td class="line">13</td><td class="hits"></td><td class="source"> * @param game</td></tr><tr><td class="line">14</td><td class="hits"></td><td class="source"> *            {string} Game identifier</td></tr><tr><td class="line">15</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">16</td><td class="hits"></td><td class="source"> * @class Session</td></tr><tr><td class="line">17</td><td class="hits"></td><td class="source"> * @author jmanero</td></tr><tr><td class="line">18</td><td class="hits"></td><td class="source"> * @version 4/21/2012</td></tr><tr><td class="line">19</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">20</td><td class="hits">1</td><td class="source">var Session = function(id) {</td></tr><tr class="hit"><td class="line">21</td><td class="hits">3</td><td class="source">	var self = this;</td></tr><tr><td class="line">22</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">23</td><td class="hits">3</td><td class="source">	this.id = id;</td></tr><tr class="hit"><td class="line">24</td><td class="hits">3</td><td class="source">	this.game = '';</td></tr><tr class="hit"><td class="line">25</td><td class="hits">3</td><td class="source">	this.socket = new net.Socket();</td></tr><tr><td class="line">26</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">27</td><td class="hits">3</td><td class="source">	this.lastAccess = Date.now();</td></tr><tr><td class="line">28</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">29</td><td class="hits">3</td><td class="source">	this.request = {};</td></tr><tr class="hit"><td class="line">30</td><td class="hits">3</td><td class="source">	this.response = {};</td></tr><tr><td class="line">31</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">32</td><td class="hits">3</td><td class="source">	this.clientBuffer = [];</td></tr><tr class="hit"><td class="line">33</td><td class="hits">3</td><td class="source">	this.clientConnected = false;</td></tr><tr><td class="line">34</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">35</td><td class="hits">3</td><td class="source">	this.serverBuffer = [];</td></tr><tr class="hit"><td class="line">36</td><td class="hits">3</td><td class="source">	this.serverConnected = false;</td></tr><tr><td class="line">37</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">38</td><td class="hits">3</td><td class="source">	this.destroyFlag = false;</td></tr><tr><td class="line">39</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">40</td><td class="hits"></td><td class="source">	// Send buffer once connected</td></tr><tr class="hit"><td class="line">41</td><td class="hits">3</td><td class="source">	this.socket.on('connect', function() {</td></tr><tr class="hit"><td class="line">42</td><td class="hits">1</td><td class="source">		debug.log(&quot;	Connected to server&quot;);</td></tr><tr class="hit"><td class="line">43</td><td class="hits">1</td><td class="source">		self.serverConnected = true;</td></tr><tr><td class="line">44</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">45</td><td class="hits"></td><td class="source">		// Only one request per packet!</td></tr><tr class="hit"><td class="line">46</td><td class="hits">1</td><td class="source">		while (self.serverBuffer.length &gt; 0) {</td></tr><tr class="hit"><td class="line">47</td><td class="hits">1</td><td class="source">			var xmlReq = self.serverBuffer.shift().toXML();</td></tr><tr class="miss"><td class="line">48</td><td class="hits">0</td><td class="source">			debug.log(&quot;	Server &lt;-- &quot; + xmlReq + &quot; &lt;-- Buffer&quot;);</td></tr><tr><td class="line">49</td><td class="hits"></td><td class="source"> </td></tr><tr class="miss"><td class="line">50</td><td class="hits">0</td><td class="source">			this.write(xmlReq + &quot;\n&quot;);</td></tr><tr><td class="line">51</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">52</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">53</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">54</td><td class="hits"></td><td class="source">	// On data from server, send to client or buffer</td></tr><tr class="hit"><td class="line">55</td><td class="hits">3</td><td class="source">	this.socket.on('data', function(data) {</td></tr><tr class="miss"><td class="line">56</td><td class="hits">0</td><td class="source">		var xmlData = data.toString(); // Ensure that data isn't a buffer</td></tr><tr class="miss"><td class="line">57</td><td class="hits">0</td><td class="source">		new ccResponse().handle(xmlData, self);</td></tr><tr><td class="line">58</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">59</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">60</td><td class="hits"></td><td class="source">	// Error Handler</td></tr><tr class="hit"><td class="line">61</td><td class="hits">3</td><td class="source">	this.socket.on('error', function(e) {</td></tr><tr class="miss"><td class="line">62</td><td class="hits">0</td><td class="source">		self.toClient(new mResponse().serverError(502,</td></tr><tr><td class="line">63</td><td class="hits"></td><td class="source">				&quot;Unable to connect to DLServer&quot;));</td></tr><tr class="miss"><td class="line">64</td><td class="hits">0</td><td class="source">		self.serverConnected = false;</td></tr><tr><td class="line">65</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">66</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">67</td><td class="hits"></td><td class="source">	// Handle server-side closure</td></tr><tr class="hit"><td class="line">68</td><td class="hits">3</td><td class="source">	this.socket.on('end', function() {</td></tr><tr class="miss"><td class="line">69</td><td class="hits">0</td><td class="source">		if (!self.destroyFlag) {</td></tr><tr class="miss"><td class="line">70</td><td class="hits">0</td><td class="source">			self.toClient(new mResponse().serverError(502,</td></tr><tr><td class="line">71</td><td class="hits"></td><td class="source">					&quot;DLServer has closed connection&quot;));</td></tr><tr><td class="line">72</td><td class="hits"></td><td class="source"> </td></tr><tr class="miss"><td class="line">73</td><td class="hits">0</td><td class="source">			self.releaseClient();</td></tr><tr class="miss"><td class="line">74</td><td class="hits">0</td><td class="source">			self.destroyFlag = true;</td></tr><tr><td class="line">75</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">76</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">77</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">78</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">79</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">80</td><td class="hits"></td><td class="source"> * Send data and line break to DLServer</td></tr><tr><td class="line">81</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">82</td><td class="hits"></td><td class="source"> * @param data</td></tr><tr><td class="line">83</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">84</td><td class="hits">1</td><td class="source">Session.prototype.toServer = function(req) {</td></tr><tr class="hit"><td class="line">85</td><td class="hits">1</td><td class="source">	if (this.serverConnected) {</td></tr><tr class="miss"><td class="line">86</td><td class="hits">0</td><td class="source">		debug.log(&quot;	Server &lt;-- &quot; + req.toXML() + &quot; &lt;-- Client&quot;);</td></tr><tr class="miss"><td class="line">87</td><td class="hits">0</td><td class="source">		this.socket.write(req.toXML() + &quot;\n&quot;);</td></tr><tr><td class="line">88</td><td class="hits"></td><td class="source">	} else {</td></tr><tr class="hit"><td class="line">89</td><td class="hits">1</td><td class="source">		debug.log(&quot;	Buffer &lt;-- &quot; + JSON.stringify(req) + &quot; &lt;-- Client&quot;);</td></tr><tr class="hit"><td class="line">90</td><td class="hits">1</td><td class="source">		this.serverBuffer.push(req);</td></tr><tr><td class="line">91</td><td class="hits"></td><td class="source">	}</td></tr><tr><td class="line">92</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">93</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">94</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">95</td><td class="hits"></td><td class="source"> * Send response data to client</td></tr><tr><td class="line">96</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">97</td><td class="hits"></td><td class="source"> * @param response</td></tr><tr><td class="line">98</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">99</td><td class="hits">1</td><td class="source">Session.prototype.toClient = function(res) {</td></tr><tr class="hit"><td class="line">100</td><td class="hits">2</td><td class="source">	if (this.clientConnected) {</td></tr><tr class="miss"><td class="line">101</td><td class="hits">0</td><td class="source">		this.clientConnected = false;</td></tr><tr><td class="line">102</td><td class="hits"></td><td class="source">		</td></tr><tr class="miss"><td class="line">103</td><td class="hits">0</td><td class="source">		if (!Array.isArray(res)) {</td></tr><tr class="miss"><td class="line">104</td><td class="hits">0</td><td class="source">			res = [ res ];</td></tr><tr><td class="line">105</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">106</td><td class="hits"></td><td class="source"> </td></tr><tr class="miss"><td class="line">107</td><td class="hits">0</td><td class="source">		debug.log(&quot;	Server --&gt; &quot; + JSON.stringify(res) + &quot; --&gt; Client&quot;);</td></tr><tr><td class="line">108</td><td class="hits"></td><td class="source"> </td></tr><tr class="miss"><td class="line">109</td><td class="hits">0</td><td class="source">		this.response.send(res);</td></tr><tr class="miss"><td class="line">110</td><td class="hits">0</td><td class="source">		this.releaseClient();</td></tr><tr><td class="line">111</td><td class="hits"></td><td class="source">	} else {</td></tr><tr class="hit"><td class="line">112</td><td class="hits">2</td><td class="source">		debug.log(&quot;	Server --&gt; &quot; + JSON.stringify(res) + &quot; --&gt; Buffer&quot;);</td></tr><tr class="hit"><td class="line">113</td><td class="hits">2</td><td class="source">		this.clientBuffer.push(res);</td></tr><tr><td class="line">114</td><td class="hits"></td><td class="source">	}</td></tr><tr><td class="line">115</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">116</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">117</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">118</td><td class="hits"></td><td class="source"> * Connect internal socket to DLServer</td></tr><tr><td class="line">119</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">120</td><td class="hits">1</td><td class="source">Session.prototype.start = function(port, host) {</td></tr><tr class="hit"><td class="line">121</td><td class="hits">1</td><td class="source">	if (!this.serverConnected) {</td></tr><tr class="hit"><td class="line">122</td><td class="hits">1</td><td class="source">		try {</td></tr><tr class="hit"><td class="line">123</td><td class="hits">1</td><td class="source">			var h = host || common.DLServer.host || &quot;127.0.0.1&quot;;</td></tr><tr class="hit"><td class="line">124</td><td class="hits">1</td><td class="source">			var p = port || common.DLServer.port;</td></tr><tr class="hit"><td class="line">125</td><td class="hits">1</td><td class="source">			this.socket.connect(p, h);</td></tr><tr><td class="line">126</td><td class="hits"></td><td class="source">		} catch (e) {</td></tr><tr class="miss"><td class="line">127</td><td class="hits">0</td><td class="source">			this.serverConnected = false;</td></tr><tr><td class="line">128</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">129</td><td class="hits"></td><td class="source">	}</td></tr><tr><td class="line">130</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">131</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">132</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">133</td><td class="hits"></td><td class="source"> * Save temporary client connection</td></tr><tr><td class="line">134</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">135</td><td class="hits"></td><td class="source"> * @param req</td></tr><tr><td class="line">136</td><td class="hits"></td><td class="source"> * @param res</td></tr><tr><td class="line">137</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">138</td><td class="hits">1</td><td class="source">Session.prototype.bindClient = function(req, res, next) {</td></tr><tr class="miss"><td class="line">139</td><td class="hits">0</td><td class="source">	this.lastAccess = Date.now();</td></tr><tr class="miss"><td class="line">140</td><td class="hits">0</td><td class="source">	var self = this;</td></tr><tr><td class="line">141</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">142</td><td class="hits"></td><td class="source">	// Handle client-side closure</td></tr><tr class="miss"><td class="line">143</td><td class="hits">0</td><td class="source">	req.on('close', function() {</td></tr><tr class="miss"><td class="line">144</td><td class="hits">0</td><td class="source">		debug.log(&quot;	Browser closed connection: &quot; + self.id);</td></tr><tr class="miss"><td class="line">145</td><td class="hits">0</td><td class="source">		self.releaseClient();</td></tr><tr><td class="line">146</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">147</td><td class="hits"></td><td class="source"> </td></tr><tr class="miss"><td class="line">148</td><td class="hits">0</td><td class="source">	req.on('end', function() {</td></tr><tr class="miss"><td class="line">149</td><td class="hits">0</td><td class="source">		debug.log(&quot;	Browser sent FIN: &quot; + self.id);</td></tr><tr><td class="line">150</td><td class="hits"></td><td class="source">//		self.releaseClient();</td></tr><tr><td class="line">151</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">152</td><td class="hits"></td><td class="source">	// -------</td></tr><tr><td class="line">153</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">154</td><td class="hits"></td><td class="source">	</td></tr><tr class="miss"><td class="line">155</td><td class="hits">0</td><td class="source">	debug.log(&quot;	Client Bound: &quot; + this.id);</td></tr><tr class="miss"><td class="line">156</td><td class="hits">0</td><td class="source">	this.request = req;</td></tr><tr class="miss"><td class="line">157</td><td class="hits">0</td><td class="source">	this.response = res;</td></tr><tr class="miss"><td class="line">158</td><td class="hits">0</td><td class="source">	this.clientConnected = true;</td></tr><tr class="miss"><td class="line">159</td><td class="hits">0</td><td class="source">	next();</td></tr><tr><td class="line">160</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">161</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">162</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">163</td><td class="hits"></td><td class="source"> * Clear temporary client connection information</td></tr><tr><td class="line">164</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">165</td><td class="hits">1</td><td class="source">Session.prototype.releaseClient = function() {</td></tr><tr class="miss"><td class="line">166</td><td class="hits">0</td><td class="source">	this.clientConnected = false;</td></tr><tr class="miss"><td class="line">167</td><td class="hits">0</td><td class="source">	this.request = {};</td></tr><tr class="miss"><td class="line">168</td><td class="hits">0</td><td class="source">	this.response = {};</td></tr><tr class="miss"><td class="line">169</td><td class="hits">0</td><td class="source">	debug.log(&quot;	Client Released: &quot; + this.id);</td></tr><tr><td class="line">170</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">171</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">172</td><td class="hits">1</td><td class="source">Session.prototype.destroy = function() {</td></tr><tr class="miss"><td class="line">173</td><td class="hits">0</td><td class="source">	this.destroyFlag = true;</td></tr><tr class="miss"><td class="line">174</td><td class="hits">0</td><td class="source">	this.socket.end();</td></tr><tr class="miss"><td class="line">175</td><td class="hits">0</td><td class="source">	this.releaseClient();</td></tr><tr><td class="line">176</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">177</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">178</td><td class="hits">1</td><td class="source">module.exports = Session;</td></tr></tbody></table></div><div class="file"><h2 id="common.js">common.js</h2><div id="stats" class="high"><div class="percentage">100%</div><div class="sloc">2</div><div class="hits">2</div><div class="misses">0</div></div><table id="source"><thead><tr><th>Line</th><th>Hits</th><th>Source</th></tr></thead><tbody><tr><td class="line">1</td><td class="hits"></td><td class="source">/*</td></tr><tr><td class="line">2</td><td class="hits"></td><td class="source"> * Config settings to be used when the DL proxy</td></tr><tr><td class="line">3</td><td class="hits"></td><td class="source"> * is launched.</td></tr><tr><td class="line">4</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">5</td><td class="hits"></td><td class="source"> * Author: John Manero</td></tr><tr><td class="line">6</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">7</td><td class="hits">1</td><td class="source">var common = {</td></tr><tr><td class="line">8</td><td class="hits"></td><td class="source">	DLServer : {</td></tr><tr><td class="line">9</td><td class="hits"></td><td class="source">		host : 'pawtucket.ece.wpi.edu', //'130.215.23.42', //'ccasola.dyndns.biz', //'127.0.0.1', </td></tr><tr><td class="line">10</td><td class="hits"></td><td class="source">		port : 9371</td></tr><tr><td class="line">11</td><td class="hits"></td><td class="source">	},</td></tr><tr><td class="line">12</td><td class="hits"></td><td class="source">	client : {</td></tr><tr><td class="line">13</td><td class="hits"></td><td class="source">		timeout : 30 * 1000, // 30 seconds</td></tr><tr><td class="line">14</td><td class="hits"></td><td class="source">		</td></tr><tr><td class="line">15</td><td class="hits"></td><td class="source">	},</td></tr><tr><td class="line">16</td><td class="hits"></td><td class="source">	session : {</td></tr><tr><td class="line">17</td><td class="hits"></td><td class="source">		reapInterval : 5 * 1000, // 5 Seconds</td></tr><tr><td class="line">18</td><td class="hits"></td><td class="source">		maxLen : 3600 * 1000 // 1 Hour</td></tr><tr><td class="line">19</td><td class="hits"></td><td class="source">	}</td></tr><tr><td class="line">20</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">21</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">22</td><td class="hits">1</td><td class="source">module.exports = common;</td></tr></tbody></table></div><div class="file"><h2 id="control/ResponseHooks.js">control/ResponseHooks.js</h2><div id="stats" class="high"><div class="percentage">100%</div><div class="sloc">15</div><div class="hits">15</div><div class="misses">0</div></div><table id="source"><thead><tr><th>Line</th><th>Hits</th><th>Source</th></tr></thead><tbody><tr class="hit"><td class="line">1</td><td class="hits">1</td><td class="source">var xml2js = require('xml2js');</td></tr><tr><td class="line">2</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">3</td><td class="hits">1</td><td class="source">var parser = new xml2js.Parser({</td></tr><tr><td class="line">4</td><td class="hits"></td><td class="source">	mergeAttrs : true</td></tr><tr><td class="line">5</td><td class="hits"></td><td class="source">});</td></tr><tr><td class="line">6</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">7</td><td class="hits">1</td><td class="source">var Response = function() {</td></tr><tr><td class="line">8</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">9</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">10</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">11</td><td class="hits">1</td><td class="source">Response.prototype.handle = function(data, session) {</td></tr><tr class="hit"><td class="line">12</td><td class="hits">2</td><td class="source">	parser.parseString(data, function(e, response) {</td></tr><tr class="hit"><td class="line">13</td><td class="hits">2</td><td class="source">		session.toClient(response);</td></tr><tr><td class="line">14</td><td class="hits"></td><td class="source">		</td></tr><tr><td class="line">15</td><td class="hits"></td><td class="source">//		response = response.response || {};</td></tr><tr><td class="line">16</td><td class="hits"></td><td class="source">		</td></tr><tr><td class="line">17</td><td class="hits"></td><td class="source">		// Response Hooks</td></tr><tr class="hit"><td class="line">18</td><td class="hits">2</td><td class="source">		if(typeof(response.signInResponse) == 'object') { // Signin</td></tr><tr class="hit"><td class="line">19</td><td class="hits">1</td><td class="source">			var signInResponse = response.signInResponse;</td></tr><tr><td class="line">20</td><td class="hits"></td><td class="source">			</td></tr><tr class="hit"><td class="line">21</td><td class="hits">1</td><td class="source">			if(signInResponse.id) {</td></tr><tr class="hit"><td class="line">22</td><td class="hits">1</td><td class="source">				session.game = signInResponse.id;</td></tr><tr><td class="line">23</td><td class="hits"></td><td class="source">			}</td></tr><tr class="hit"><td class="line">24</td><td class="hits">1</td><td class="source">		} else if(typeof(response.createResponse) == 'object') { // Create</td></tr><tr class="hit"><td class="line">25</td><td class="hits">1</td><td class="source">			var createResponse = response.createResponse;</td></tr><tr><td class="line">26</td><td class="hits"></td><td class="source">			</td></tr><tr class="hit"><td class="line">27</td><td class="hits">1</td><td class="source">			if(createResponse.id) {</td></tr><tr class="hit"><td class="line">28</td><td class="hits">1</td><td class="source">				session.game = createResponse.id;</td></tr><tr><td class="line">29</td><td class="hits"></td><td class="source">			}</td></tr><tr><td class="line">30</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">31</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">32</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">33</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">34</td><td class="hits">1</td><td class="source">module.exports = Response;</td></tr></tbody></table></div><div class="file"><h2 id="model/ResponseEntity.js">model/ResponseEntity.js</h2><div id="stats" class="high"><div class="percentage">100%</div><div class="sloc">6</div><div class="hits">6</div><div class="misses">0</div></div><table id="source"><thead><tr><th>Line</th><th>Hits</th><th>Source</th></tr></thead><tbody><tr class="hit"><td class="line">1</td><td class="hits">1</td><td class="source">var Response = function() {</td></tr><tr><td class="line">2</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">3</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">4</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">5</td><td class="hits">1</td><td class="source">Response.prototype.clientError = function(code, message) {</td></tr><tr class="hit"><td class="line">6</td><td class="hits">1</td><td class="source">	return {</td></tr><tr><td class="line">7</td><td class="hits"></td><td class="source">		response : {</td></tr><tr><td class="line">8</td><td class="hits"></td><td class="source">			code : 400,</td></tr><tr><td class="line">9</td><td class="hits"></td><td class="source">			status : &quot;error&quot;,</td></tr><tr><td class="line">10</td><td class="hits"></td><td class="source">			error : {</td></tr><tr><td class="line">11</td><td class="hits"></td><td class="source">				code : code,</td></tr><tr><td class="line">12</td><td class="hits"></td><td class="source">				message : message</td></tr><tr><td class="line">13</td><td class="hits"></td><td class="source">			}</td></tr><tr><td class="line">14</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">15</td><td class="hits"></td><td class="source">	};</td></tr><tr><td class="line">16</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">17</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">18</td><td class="hits">1</td><td class="source">Response.prototype.serverError = function(code, message) {</td></tr><tr class="hit"><td class="line">19</td><td class="hits">1</td><td class="source">	return {</td></tr><tr><td class="line">20</td><td class="hits"></td><td class="source">		response : {</td></tr><tr><td class="line">21</td><td class="hits"></td><td class="source">			code : 500,</td></tr><tr><td class="line">22</td><td class="hits"></td><td class="source">			status : &quot;error&quot;,</td></tr><tr><td class="line">23</td><td class="hits"></td><td class="source">			error : {</td></tr><tr><td class="line">24</td><td class="hits"></td><td class="source">				code : code,</td></tr><tr><td class="line">25</td><td class="hits"></td><td class="source">				message : message</td></tr><tr><td class="line">26</td><td class="hits"></td><td class="source">			}</td></tr><tr><td class="line">27</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">28</td><td class="hits"></td><td class="source">	};</td></tr><tr><td class="line">29</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">30</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">31</td><td class="hits">1</td><td class="source">module.exports = Response;</td></tr></tbody></table></div><div class="file"><h2 id="control/CommandControl.js">control/CommandControl.js</h2><div id="stats" class="terrible"><div class="percentage">22%</div><div class="sloc">18</div><div class="hits">4</div><div class="misses">14</div></div><table id="source"><thead><tr><th>Line</th><th>Hits</th><th>Source</th></tr></thead><tbody><tr><td class="line">1</td><td class="hits"></td><td class="source">/*</td></tr><tr><td class="line">2</td><td class="hits"></td><td class="source"> * This file deals with all requests to the</td></tr><tr><td class="line">3</td><td class="hits"></td><td class="source"> * /do API, that is any requests other than SignIn</td></tr><tr><td class="line">4</td><td class="hits"></td><td class="source"> * and Ping.</td></tr><tr><td class="line">5</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">6</td><td class="hits"></td><td class="source"> * Author: John Manero</td></tr><tr><td class="line">7</td><td class="hits"></td><td class="source"> * Contributor: Chris Casola</td></tr><tr><td class="line">8</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">9</td><td class="hits">1</td><td class="source">var mRespomnse = require('../model/ResponseEntity');</td></tr><tr class="hit"><td class="line">10</td><td class="hits">1</td><td class="source">var uuid = require('node-uuid');</td></tr><tr><td class="line">11</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">12</td><td class="hits"></td><td class="source">/**</td></tr><tr><td class="line">13</td><td class="hits"></td><td class="source"> * Send commands to the DLServer</td></tr><tr><td class="line">14</td><td class="hits"></td><td class="source"> * </td></tr><tr><td class="line">15</td><td class="hits"></td><td class="source"> */</td></tr><tr class="hit"><td class="line">16</td><td class="hits">1</td><td class="source">var Command = function(app) {</td></tr><tr class="miss"><td class="line">17</td><td class="hits">0</td><td class="source">	app.post('/do', function(req, res) {</td></tr><tr class="miss"><td class="line">18</td><td class="hits">0</td><td class="source">		var request = req.body;</td></tr><tr class="miss"><td class="line">19</td><td class="hits">0</td><td class="source">		var session = req.session;</td></tr><tr><td class="line">20</td><td class="hits"></td><td class="source">		</td></tr><tr><td class="line">21</td><td class="hits"></td><td class="source">		// Only connect to server after a command/keepalive request</td></tr><tr class="miss"><td class="line">22</td><td class="hits">0</td><td class="source">		session.start();</td></tr><tr><td class="line">23</td><td class="hits"></td><td class="source">		</td></tr><tr class="miss"><td class="line">24</td><td class="hits">0</td><td class="source">		if(!Array.isArray(request)) {</td></tr><tr class="miss"><td class="line">25</td><td class="hits">0</td><td class="source">			request = [request];</td></tr><tr><td class="line">26</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">27</td><td class="hits"></td><td class="source">		</td></tr><tr class="miss"><td class="line">28</td><td class="hits">0</td><td class="source">		for(var r = 0; r &lt; request.length; r++) {</td></tr><tr class="miss"><td class="line">29</td><td class="hits">0</td><td class="source">			debug.log(&quot;Request XML: &quot; + request.toXML());</td></tr><tr class="miss"><td class="line">30</td><td class="hits">0</td><td class="source">			session.toServer(request[r]);</td></tr><tr><td class="line">31</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">32</td><td class="hits"></td><td class="source">		</td></tr><tr class="miss"><td class="line">33</td><td class="hits">0</td><td class="source">		if (session.clientBuffer.length &gt; 0) {</td></tr><tr class="miss"><td class="line">34</td><td class="hits">0</td><td class="source">			debug.log(&quot;	Buffer --&gt; &quot; + JSON.stringify(session.clientBuffer) + &quot; --&gt; Client&quot;);</td></tr><tr class="miss"><td class="line">35</td><td class="hits">0</td><td class="source">			res.send(session.clientBuffer);</td></tr><tr class="miss"><td class="line">36</td><td class="hits">0</td><td class="source">			session.clientBuffer = [];</td></tr><tr class="miss"><td class="line">37</td><td class="hits">0</td><td class="source">			session.releaseClient();</td></tr><tr><td class="line">38</td><td class="hits"></td><td class="source">		}</td></tr><tr><td class="line">39</td><td class="hits"></td><td class="source">	});</td></tr><tr><td class="line">40</td><td class="hits"></td><td class="source">};</td></tr><tr><td class="line">41</td><td class="hits"></td><td class="source"> </td></tr><tr class="hit"><td class="line">42</td><td class="hits">1</td><td class="source">exports.create = Command;</td></tr></tbody></table></div></div></div></body></html>